package com.gzu.shop.handler;

import com.gzu.shop.common.Result;
import com.gzu.shop.common.ResultStatus;
import com.gzu.shop.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author clown
 */

@RestControllerAdvice // @ControllerAdvice + @ResponseBody
@Slf4j
public class ControllerExceptionHandler {

    @ExceptionHandler(BaseException.class)
    public Result<Object> resultStatusException(BaseException e) {
        log.error("异常信息：{}", e.getMessage());
        return Result.error(ResultStatus.UNKNOWN_ERROR, e.getMessage());
    }
}
